<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div><i class="el-icon-user-solid"/>用户总数</div>
          <div style="padding-left:10px;text-align: center;font-weight: bold">
           {{total}}
          </div>
        </el-card>
<!--      </el-col>-->
<!--      <el-col :span="6">-->
<!--        <el-card style="color: #F56C6C">-->
<!--          <div><i class="el-icon-money"/>销量总量</div>-->
<!--          <div style="padding-left:10px;text-align: center;font-weight: bold">-->
<!--            100-->
<!--          </div>-->
<!--        </el-card>-->
<!--      </el-col>-->
<!--      <el-col :span="6">-->
<!--        <el-card style="color: #67C23A">-->
<!--          <div><i class="el-icon-bank-card"/>收益总额</div>-->
<!--          <div style="padding-left:10px;text-align: center;font-weight: bold">-->
<!--            100-->
<!--          </div>-->
<!--        </el-card>-->
<!--      </el-col>-->
<!--      <el-col :span="6">-->
<!--        <el-card style="color: #E6A23C">-->
<!--          <div><i class="el-icon-s-shop"/>门店总数</div>-->
<!--          <div style="padding-left:10px;text-align: center;font-weight: bold">-->
<!--            100-->
<!--          </div>-->
<!--        </el-card>-->
      </el-col>

    </el-row>

    <el-row>
      <el-col :span="12">
        <el-card id="main" style="width: 500px;height: 400px"></el-card>
      </el-col>
      <el-col :span="12">
        <el-card id="pie" style="width: 500px;height: 400px"></el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  name: "Home",
  data() {
    return {
      total:0,
      user:localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    }
  },
  mounted() {
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
      title: {
        text: '各季度会员统计',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: ['第一季度','第二季度','第三季度','第四季度']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name:"会员",
          data: [],
          type: 'bar'
        },
        {
          name:"会员",
          data: [],
          type: 'line'
        },
        {
          name:"测试用的",
          data: [4,5,6,7],
          type: 'bar'
        },
        {
          name:"测试用的",
          data: [4,5,6,7],
          type: 'line'
        },
      ]
    };

    //饼图
    var chartDom2 = document.getElementById('pie');
    var myChart2 = echarts.init(chartDom2);
    var option2;
    option2 = {
      title: {
        text: '各季度会员统计',
        subtext: '饼图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          type: 'pie',
          radius: '50%',
          data: [],
          label: {
            //echarts饼图内部显示百分比设置
            show: true,
            position: "inside", //outside 外部显示  inside 内部显示
            formatter: `{d}%`,
            color: "#ffffff", //颜色
            fontSize: 12 //字体大小
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };


    this.request.get("/echarts/data").then(res=>{
      console.log(res)
      // option.xAxis.data=res.data.x
      option.series[0].data=res.data    //series因为它本身也是一个数组，必须指定坐标series[0]
      option.series[1].data=res.data   //series因为它本身也是一个数组，必须指定坐标series[1]


      option && myChart.setOption(option);

      option2.series[0].data =[
        {name:"第一季度",value:res.data[0]},
        {name:"第二季度",value:res.data[1]},
        {name:"第三季度",value:res.data[2]},
        {name:"第四季度",value:res.data[3]},
      ]
      option && myChart2.setOption(option2);
    })

    this.request("/echarts/total").then(res=>{
      this.total=res.data
    })
  }
}
</script>

<style scoped>

</style>